package com.example.barcodeapp.utils;

import android.os.Looper;
import android.widget.Toast;

import com.example.barcodeapp.app.MyApp;


/**
 * FileName: Show
 * Author: LJT
 * Date: 2019/9/6 17:09
 * Description: ${DESCRIPTION}
 */


public class Show {
    static Toast toast = null;
    public static void showMessage(String message) {
        try {
            if(toast!=null){
                toast.setText(message);
            }else{
                toast= Toast.makeText(MyApp.getInstance().getApplicationContext(), message, Toast.LENGTH_SHORT);
            }
            toast.show();
        } catch (Exception e) {
            //解决在子线程中调用Toast的异常情况处理
            Looper.prepare();
            Toast.makeText(MyApp.getInstance().getApplicationContext(), message, Toast.LENGTH_SHORT).show();
            Looper.loop();
        }
    }
}
